<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="工作报告" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea v-model="model.remark"
                rows="12"
                placeholder="请输入报告内容" autosize="true"
                />
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="报告日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="date">
              <a-date-picker
                v-model="model.date"
                value-format="YYYY-MM-DD"
                style="width: 210px"
                format="YYYY-MM-DD"
                :bordered="false"
                :placeholder="'报告日期'"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import {httpAction} from '@/api/manage'

export default {
  name: 'SysUserDailyForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      },
      confirmLoading: false,
      validatorRules:{
        remark:[{required: true, message: '请输入报告内容!'}]
      },
      url: {
        add: "/system/sysUserDaily/add",
        edit: "/system/sysUserDaily/edit",
        queryById: "/system/sysUserDaily/queryById"
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add() {
      this.model = {};
      this.model.remark = "工作报告\n" +
        "今日的工作内容：\n" +
        "明天的工作计划： \n" +
        "遇到的问题：";
      this.edit(this.model);
    },
    edit(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  }
}
</script>